package jwdt.xadmin.goods.service.impl;

import java.util.List;
import java.util.Map;

import jwdt.common.dao.BaseDao;
import jwdt.xadmin.goods.bean.TGoods;
import jwdt.xadmin.goods.service.GoodsManageService;

import com.ezerg.db.Jdb;
import com.ezerg.db.ext.PageUtil;
import com.ezerg.util.DateUtil;

public class GoodsManageServiceImpl implements GoodsManageService {
	
	private BaseDao<TGoods> baseDao;

	public void setBaseDao(BaseDao<TGoods> baseDao) {
		this.baseDao = baseDao;
	}
	
	@Override
	public PageUtil selectGoodsList(PageUtil pu,int fid)throws Exception{
		String where = "classid=" + fid + " order by zt";
		pu.doList(TGoods.class,where);
		return pu;
	}
	
	@SuppressWarnings("unchecked")
	public List<Map<String, String>> selectGoods()throws Exception{
		String sql = "select goodsid,name from t_goods ";
		return Jdb.get().query(sql);
	}
	
	@Override
	public TGoods selectOneGoods(int goodsid)throws Exception{
		return baseDao.doLoadObj(TGoods.class, goodsid);
	}
	
	@Override
	public String saveGoods(int goodsid,TGoods obj)throws Exception{
		obj.setDt(DateUtil.getDateTime());
		if(goodsid==0){
			return baseDao.doAddObj(obj);
		}
		return baseDao.doUpdateObj(TGoods.class, goodsid, obj);
	}
	
	@Override
	public String delGoods(int goodsid)throws Exception{
		return baseDao.doDelObj(TGoods.class, goodsid);
	}
	
}
